package Plugin_Reprise.console;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;

import Plugin_Reprise.Activator;
import Plugin_Reprise.preferences.PreferenceConstants;
import asjava.uniobjects.UniSession;

public class MessageConsoleStream2out extends MessageConsoleStream {

	private String pathlog;

	private FileWriter bws = null;

	public MessageConsoleStream2out(MessageConsole console) {
		super(console);
		IPreferenceStore prefs = Activator.getDefault().getPreferenceStore();
		this.pathlog = prefs
				.getString(PreferenceConstants.GENE_Constants.PATH_SUIVI_REPRISE);
		String fichierlog =this.pathlog + File.separator
		+ console.getName() + ".log";
		try {
			this.bws = new FileWriter(fichierlog, true);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// TODO Auto-generated constructor stub
	}

	@Override
	public void print(String message) {
		// TODO Auto-generated method stub
		super.print(message);
		try {
			this.bws.write(message);
			this.bws.flush();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}



	
	
	@Override
	public synchronized void close() throws IOException {
		// TODO Auto-generated method stub
		this.bws.close();
		super.close();
		
	}

}
